package com.huitone.smspfm.core.config;

import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.huitone.smspfm.logger.ExtLogger;

import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import com.bin.common.utils.FileUtils;
import com.bin.common.utils.StringUtils;
import com.huitone.smspfm.context.utils.ContextPropertiesUtils;
import com.huitone.smspfm.context.utils.ContextUtils;
import com.huitone.smspfm.core.waterpipe.client.impl.SimpleGateLinkRegister;
import com.huitone.smspfm.dao.oracle.ForbidRuleDao;
import com.huitone.smspfm.dao.oracle.GateDefDao;
import com.huitone.smspfm.dao.oracle.SvrNodeDefDao;
import com.huitone.smspfm.dao.oracle.entity.ForbidRule;
import com.huitone.smspfm.dao.oracle.entity.GateDef;
import com.huitone.smspfm.dao.oracle.entity.SvrNodeDef;
import com.huitone.smspfm.redis.impl.HashOpts;
import com.huitone.smspfm.redis.impl.KeyOpts;
import com.huitone.smspfm.redis.impl.ListOpts;
import com.huitone.smspfm.redis.impl.ScriptOpts;
import com.huitone.smspfm.redis.impl.SetOpts;
import com.huitone.smspfm.redis.impl.StringOpts;
import com.huitone.smspfm.redis.impl.ZsetOpts;
import com.huitone.smspfm.redis.pipeline.PipelineOpts;
import com.huitone.smspfm.redis.pipeline.PipelineOpts.ABExcuteCommands;

/**   
* @Title StaticConfigs.java 
* @Package com.huitone.smspfm.core.config.impl 
* @Description 保存全局可用参数或者配置文件,方便程序使用以及重新加载 
* @author ybliang   
* @date 2017年5月17日 下午5:46:16 
* @version V1.0   
*/
public class AppStaticConfigs {
	
	public static ExtLogger logger = ExtLogger.create(AppStaticConfigs.class);
	
	public static String appName = StringUtils.uuid();
	
	public static String appCode = null;
	
	public static SimpleGateLinkRegister simpleGateLinkRegister = null;
	
	public static RedisSerializer<String> stringRedisSerializer = new StringRedisSerializer();
	
	
	public static final class Const{
		public final static String SMS_TEMPLATE_TYPE_WGQH = "1";
		public final static String SMS_TEMPLATE_TYPE_BT = "2";
	}
	
	
	/**
	 * 保存记录运行参数的hash的key
	 */
	public static String RunningParamsHashSet = null;
	
	/**
	 * 记录运行参数的hash
	 */
	public static String RunningParamsHash = null;
	/**
	 * 记录运行参数的hash
	 */
	public static byte[] RunningParamsHashB = null;
	
	
	// redis1
	public static KeyOpts keyOpts = null;
	public static ZsetOpts zsetOpts = null;
	public static SetOpts setOpts = null;
	public static ListOpts listOpts = null;
	public static HashOpts hashOpts = null;
	public static StringOpts stringOpts = null;
	public static PipelineOpts pipelineOpts = null;
	public static ScriptOpts scriptOpts = null;
	
	// redis2
	public static KeyOpts keyOpts2 = null;
	public static ZsetOpts zsetOpts2 = null;
	public static SetOpts setOpts2 = null;
	public static ListOpts listOpts2 = null;
	public static HashOpts hashOpts2 = null;
	public static StringOpts stringOpts2 = null;
	public static PipelineOpts pipelineOpts2 = null;
	public static ScriptOpts scriptOpts2 = null;
	
	// redis3
	public static KeyOpts keyOpts3 = null;
	public static ZsetOpts zsetOpts3 = null;
	public static SetOpts setOpts3 = null;
	public static ListOpts listOpts3 = null;
	public static HashOpts hashOpts3 = null;
	public static StringOpts stringOpts3 = null;
	public static PipelineOpts pipelineOpts3 = null;
	public static ScriptOpts scriptOpts3 = null;
	
	
	/**
	 * 是否开启定时重载配置信息
	 */
	public static boolean reloadConfigTimingOnOff = false;
	
	/**
	 * 重载配置信息的时间间隔(单位/分钟), 只有reloadConfigTimingOnOff=true该参数才生效
	 */
	public static int reloadConfigInterval = 10;
	
	/**
	 * 是否开启缓存队列禁发过滤
	 */
	
	public static boolean forbiddenTimeFilterOnOff = true;
	
	
	/**
	 * 业务端定义列表
	 */
	public static List<SvrNodeDef> configSvrNodeDefList = null;
	
	/**
	 * 禁发时段[srvNode:serviceCode:startTime:endTime:forbidruleId]
	 */
	//public static String configForbidTimeZSet = null;
	public static Map<String,Set<String>> configForbidTimeMap = new HashMap<>();
	
	/**
	 * 通道定义表
	 */
	public static Map<String,GateDef> configGateDefMap = new HashMap<String, GateDef>();	
	/**
	 * 通道线程配置集合
	 */
	public static Map<String,Integer> configGateLinkThreadNumMap = new HashMap<String, Integer>();	
	
	public static String gatelinkSendThreadNum = "";
	
	/**
	 * 通道发送速率默认值
	 */
	public static Long gateMaxFlow = 0l;
	
	/**
	 * 通道发送队列与发送速率的对比 
	 */
	public static Integer sendQueueMaxProcess = 1;
	/**
	 * 缓存队列单次处理长度
	 */
	public static Long cacheQueueProcessingNum = 0l;
	
	
	/**
	 * 集合,用于存放优先级队列名
	 */
	public static String iSMPriListNamesSet = null;
	/**
	 * 集合,用于存放优先级队列名
	 */
	public static byte[] iSMPriListNamesSetB = null;
	
	/**
	 * 短信实体保存的KEY
	 */
	public static String pSMCacheHash = null;
	public static byte[] pSMCacheHashB = null;
	/**
	 * 禁发时段队列
	 */
	public static String iSMForbidZSet = null;
	public static byte[] iSMForbidZSetB = null;
	
	
	// lua 脚本开始
	public static String luaGetSmsCache = null;
	public static String luaBlackChecker = null;
	public static String luaRepeatChecker = null;
	public static String luaGetForbid = null;
	public static String luaGetMoSms = null;
	public static String luaMoSmsBlackChecker = null;
	public static String luaGetRebuildPri = null;
	public static String luaGetPriListLength = null;

	public static String luaTransferPriList = null;
	
	public static String luaGetCallTestList = null;
	public static String luaGetCallTestListKeys = null;
	
	public static String luaGetCacheListName = null;
	public static String luaGetCacheQueueSms = null;
	public static String luaGetCacheQueueLength = null;
	// lua 脚本结束
	
	
	/**
	 * 缓存队列处理纯程池大小
	 */
	public static int cacheQueueExcutePoolSize = 1;
	
	/**
	 * 缓存队列列表KEY
	 */
	public static String isCacheQueueListKey = "SMCacheListNamesSet";
	public static byte[] isCacheQueueListKeyB = null;
	/**
	 * 缓存队列列列表查询最大个数
	 */
	public static int isCacheQueueListQuerySize = 1000 ;
	
	static {
		ContextUtils.getInstance();
	}
	
	/**
	 * 初始化静态参数
	 */
	public static void init() {
		initRedisDataStructure();
		initRedisOpts();
		initOracleConfig2();
		initLuaScript();
	}
	
	public static void reload() {
		init();
	}
	
	private static void initLuaScript() {
		
		
		boolean isWindows = System.getProperty("os.name").indexOf("Window") >= 0;
		
		// 获取SmsCache列表的短信
		StringBuffer bufferGetSmsCache = null;
		if(isWindows){
			try {
				String path = AppStaticConfigs.class.getClassLoader().getResource("lua/getsmscache.lua").getPath().substring(1).replace("/", "\\\\");
				bufferGetSmsCache = FileUtils.read(new FileInputStream(path));
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {	
			bufferGetSmsCache = FileUtils.read(AppStaticConfigs.class.getClassLoader().getResourceAsStream("lua/getsmscache.lua"));
		}		
		if (bufferGetSmsCache != null) {
			luaGetSmsCache = bufferGetSmsCache.toString();
		}
		
		// 黑名单判断lua
		StringBuffer stringBuffer1 = null;
		if(isWindows){
			try {
				String path = AppStaticConfigs.class.getClassLoader().getResource("lua/blackchecker.lua").getPath().substring(1).replace("/", "\\\\");
				stringBuffer1 = FileUtils.read(new FileInputStream(path));
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			stringBuffer1 = FileUtils.read(AppStaticConfigs.class.getClassLoader().getResourceAsStream("lua/blackchecker.lua"));
		}
		if (stringBuffer1 != null) {
			luaBlackChecker = stringBuffer1.toString();
		}
		
		// 重复检查 lua
		StringBuffer stringBuffer5 = null;
		if(isWindows){
			try {
				String path = AppStaticConfigs.class.getClassLoader().getResource("lua/repeatchecker.lua").getPath().substring(1).replace("/", "\\\\");
				stringBuffer5 = FileUtils.read(new FileInputStream(path));
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			stringBuffer5 = FileUtils.read(AppStaticConfigs.class.getClassLoader().getResourceAsStream("lua/repeatchecker.lua"));
		}
		if (stringBuffer5 != null) {
			luaRepeatChecker = stringBuffer5.toString();
		}
		
		// 从禁发集合中读取已过禁发时间的短信luaGetForbid
		StringBuffer bufferGetForbid = null;
		if (isWindows) {
			try {
				String path = AppStaticConfigs.class.getClassLoader()
						.getResource("lua/getforbid.lua").getPath()
						.substring(1).replace("/", "\\\\");
				bufferGetForbid = FileUtils.read(new FileInputStream(path));
				// StringBuffer bufferGetForbid =
				// FileUtils.read(SmsRouteFilterTask.class.getClassLoader().getResourceAsStream("lua/getforbid.lua"));

			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {

			bufferGetForbid = FileUtils.read(AppStaticConfigs.class
					.getClassLoader().getResourceAsStream("lua/getforbid.lua"));
		}
		if (bufferGetForbid != null) {
			luaGetForbid = bufferGetForbid.toString();
		}
		
		
		// 从上行短信队列中读取 luaGetMoSms
		StringBuffer bufferGetMoSms = null;
		if(isWindows){
			try {
				String path = AppStaticConfigs.class.getClassLoader().getResource("lua/getmosms.lua").getPath().substring(1).replace("/", "\\\\");
				bufferGetMoSms = FileUtils.read(new FileInputStream(path));
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			bufferGetMoSms = FileUtils.read(AppStaticConfigs.class.getClassLoader().getResourceAsStream("lua/getmosms.lua"));
		}
		if (bufferGetMoSms != null) {
			luaGetMoSms = bufferGetMoSms.toString();
		}
		
		// 从上行短信队列中读取 luaGetMoSms
		StringBuffer bufferMoSmsBlackChecker = null;
		if(isWindows){
			try {
				String path = AppStaticConfigs.class.getClassLoader().getResource("lua/moaddblackchecker.lua").getPath().substring(1).replace("/", "\\\\");
				bufferMoSmsBlackChecker = FileUtils.read(new FileInputStream(path));
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
		
			bufferMoSmsBlackChecker = FileUtils.read(AppStaticConfigs.class.getClassLoader().getResourceAsStream("lua/moaddblackchecker.lua"));
		}
		if (bufferMoSmsBlackChecker != null) {
			luaMoSmsBlackChecker = bufferMoSmsBlackChecker.toString();
		}
		
		// 从上行短信队列中读取 luaGetMoSms
		StringBuffer bufferGetRebuildPri = null;
		if(isWindows){
			try {
				String path = AppStaticConfigs.class.getClassLoader().getResource("lua/getrebuildPri.lua").getPath().substring(1).replace("/", "\\\\");
				bufferGetRebuildPri = FileUtils.read(new FileInputStream(path));
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
		
			bufferGetRebuildPri = FileUtils.read(AppStaticConfigs.class.getClassLoader().getResourceAsStream("lua/getrebuildPri.lua"));
		}
		if (bufferGetRebuildPri != null) {
			luaGetRebuildPri = bufferGetRebuildPri.toString();
		}
		
		// luaGetPriListLength
		StringBuffer bufferGetPriListLength = null;
		if(isWindows){
			try {
				String path = AppStaticConfigs.class.getClassLoader().getResource("lua/getprilistlength.lua").getPath().substring(1).replace("/", "\\\\");
				bufferGetPriListLength = FileUtils.read(new FileInputStream(path));
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			bufferGetPriListLength = FileUtils.read(AppStaticConfigs.class.getClassLoader().getResourceAsStream("lua/getprilistlength.lua"));
		}
		if (bufferGetPriListLength != null) {
			luaGetPriListLength = bufferGetPriListLength.toString();
		}
		
		// luaGetFriListName
		StringBuffer bufferGetPriListName = null;
		if (isWindows) {
			try {
				String path = AppStaticConfigs.class.getClassLoader()
						.getResource("lua/getCacheListName.lua").getPath()
						.substring(1).replace("/", "\\\\");
				bufferGetPriListName = FileUtils
						.read(new FileInputStream(path));

			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			bufferGetPriListName = FileUtils.read(AppStaticConfigs.class
					.getClassLoader().getResourceAsStream(
							"lua/getCacheListName.lua"));
		}
		if (bufferGetPriListName != null) {
			luaGetCacheListName = bufferGetPriListName.toString();
		}
		
		// luaGetCacheQueueSms
		StringBuffer bufferGetCacheQueueSms = null;
		if (isWindows) {
			try {
				String path = AppStaticConfigs.class.getClassLoader()
						.getResource("lua/getCacheQueueSms.lua").getPath()
						.substring(1).replace("/", "\\\\");
				bufferGetCacheQueueSms = FileUtils
						.read(new FileInputStream(path));

			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			bufferGetCacheQueueSms = FileUtils.read(AppStaticConfigs.class
					.getClassLoader().getResourceAsStream(
							"lua/getCacheQueueSms.lua"));
		}
		if (bufferGetCacheQueueSms != null) {
			luaGetCacheQueueSms = bufferGetCacheQueueSms.toString();
		}		
		
		
		// luaTransferPriList
		StringBuffer bufferTransferPriList = null;
		if (isWindows) {
			try {
				String path = AppStaticConfigs.class.getClassLoader()
						.getResource("lua/transferPriList.lua").getPath()
						.substring(1).replace("/", "\\\\");
				bufferTransferPriList = FileUtils
						.read(new FileInputStream(path));

			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			bufferTransferPriList = FileUtils.read(AppStaticConfigs.class
					.getClassLoader().getResourceAsStream(
							"lua/transferPriList.lua"));
		}
		if (bufferTransferPriList != null) {
			luaTransferPriList= bufferTransferPriList.toString();
		}
		
		// luaGetCallTestList
		StringBuffer bufferGetCallList = null;
		if (isWindows) {
			try {
				String path = AppStaticConfigs.class.getClassLoader()
						.getResource("lua/getSMCallList.lua").getPath()
						.substring(1).replace("/", "\\\\");
				bufferGetCallList = FileUtils
						.read(new FileInputStream(path));

			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			bufferGetCallList = FileUtils.read(AppStaticConfigs.class
					.getClassLoader().getResourceAsStream(
							"lua/getSMCallList.lua"));
		}
		if (bufferGetCallList != null) {
			luaGetCallTestList = bufferGetCallList.toString();
		}
		
		// luaGetCallTestListKeys
		StringBuffer bufferGetCallListKeys = null;
		if (isWindows) {
			try {
				String path = AppStaticConfigs.class.getClassLoader()
						.getResource("lua/getSMCallListKeys.lua").getPath()
						.substring(1).replace("/", "\\\\");
				bufferGetCallListKeys = FileUtils.read(new FileInputStream(path));

			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			bufferGetCallListKeys = FileUtils.read(AppStaticConfigs.class
					.getClassLoader().getResourceAsStream(
							"lua/getSMCallListKeys.lua"));
		}
		if (bufferGetCallListKeys != null) {
			luaGetCallTestListKeys = bufferGetCallListKeys.toString();
		}
		
		
		// luaGetPriListLength
		StringBuffer bufferGetCacheQueueLength = null;
		if(isWindows){
			try {
				String path = AppStaticConfigs.class.getClassLoader().getResource("lua/getCacheQueueLength.lua").getPath().substring(1).replace("/", "\\\\");
				bufferGetCacheQueueLength = FileUtils.read(new FileInputStream(path));
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			bufferGetCacheQueueLength = FileUtils.read(AppStaticConfigs.class.getClassLoader().getResourceAsStream("lua/getCacheQueueLength.lua"));
		}
		if (bufferGetCacheQueueLength != null) {
			luaGetCacheQueueLength = bufferGetCacheQueueLength.toString();
		}

	}
	
	/**
	 * 初始化Redis的数据结构名
	 */
	private static void initRedisDataStructure() {
		
		appName = StringUtils.trim(ContextPropertiesUtils.getProperty("smspfm.module.name")); 
		appCode = StringUtils.trim(ContextPropertiesUtils.getProperty("smspfm.module.code"));
		
		RunningParamsHashSet = ContextPropertiesUtils.getProperty("RunningParamsHashSet");
		RunningParamsHash = ContextPropertiesUtils.getProperty("RunningParamsHashPrefix") + ":" + appName + ":" + appCode;
		RunningParamsHashB = stringRedisSerializer.serialize(RunningParamsHash);
		
		cacheQueueExcutePoolSize = StringUtils.strToInt(ContextPropertiesUtils.getProperty("smspfm.cachequeue.excute.poolsize"),1);
		
		forbiddenTimeFilterOnOff = "on".equalsIgnoreCase(ContextPropertiesUtils.getProperty("smspfm.forbidden.time.filter")) ? true : false;
		
		pSMCacheHash = ContextPropertiesUtils.getProperty("SMCacheHashPrefix");
		pSMCacheHashB = stringRedisSerializer.serialize(pSMCacheHash);
		
		iSMForbidZSet = ContextPropertiesUtils.getProperty("SMForbidZSet");
		iSMForbidZSetB = stringRedisSerializer.serialize(iSMForbidZSet);
		
		iSMPriListNamesSet = ContextPropertiesUtils.getProperty("set.pri.list.names");
		iSMPriListNamesSetB = stringRedisSerializer.serialize(iSMPriListNamesSet);
		
		isCacheQueueListKey = ContextPropertiesUtils.getProperty("set.cache.list.names");
		isCacheQueueListKeyB = stringRedisSerializer.serialize(isCacheQueueListKey);
		
		reloadConfigTimingOnOff = StringUtils.equals("on", StringUtils.trim(ContextPropertiesUtils.getProperty("smspfm.reload.config.timing")));
		reloadConfigInterval = StringUtils.toInteger(StringUtils.trim(ContextPropertiesUtils.getProperty("smspfm.reload.config.interval")), 10, true);
		
		gateMaxFlow = StringUtils.toLong(StringUtils.trim(ContextPropertiesUtils.getProperty("smspfm.pri.max.flow")));
		cacheQueueProcessingNum = StringUtils.toLong(StringUtils.trim(ContextPropertiesUtils.getProperty("smspfm.cache.processing.num")));
		sendQueueMaxProcess = StringUtils.toInteger(StringUtils.trim(ContextPropertiesUtils.getProperty("smspfm.pri.max.flow.multiiple")));
	
		gatelinkSendThreadNum = ContextPropertiesUtils.getProperty("smspfm.gatelink.send.thread.num");
	}
	
	/**
	 * 初始化redis操作类
	 */
	private static void initRedisOpts() {
		
		initRedisOpts1();
		
		initRedisOpts2();
		
		initRedisOpts3();
	}

	public static void initRedisOpts3() {
		keyOpts3 = (KeyOpts) ContextUtils.getBean2("keyOpts3");
		zsetOpts3 = (ZsetOpts) ContextUtils.getBean2("zsetOpts3"); 
		setOpts3 = (SetOpts) ContextUtils.getBean2("setOpts3");
		listOpts3 = (ListOpts) ContextUtils.getBean2("listOpts3");
		hashOpts3 = (HashOpts) ContextUtils.getBean2("hashOpts3");
		stringOpts3 = (StringOpts) ContextUtils.getBean2("stringOpts3");
		pipelineOpts3 = (PipelineOpts) ContextUtils.getBean2("pipelineOpts3");
		scriptOpts3 = (ScriptOpts) ContextUtils.getBean2("scriptOpts3");
	}

	public static void initRedisOpts2() {
		keyOpts2 = (KeyOpts) ContextUtils.getBean2("keyOpts2");
		zsetOpts2 = (ZsetOpts) ContextUtils.getBean2("zsetOpts2"); 
		setOpts2 = (SetOpts) ContextUtils.getBean2("setOpts2");
		listOpts2 = (ListOpts) ContextUtils.getBean2("listOpts2");
		hashOpts2 = (HashOpts) ContextUtils.getBean2("hashOpts2");
		stringOpts2 = (StringOpts) ContextUtils.getBean2("stringOpts2");
		pipelineOpts2 = (PipelineOpts) ContextUtils.getBean2("pipelineOpts2");
		scriptOpts2 = (ScriptOpts) ContextUtils.getBean2("scriptOpts2");
	}

	public static void initRedisOpts1() {
		keyOpts = (KeyOpts) ContextUtils.getBean2("keyOpts");
		zsetOpts = (ZsetOpts) ContextUtils.getBean2("zsetOpts"); 
		setOpts = (SetOpts) ContextUtils.getBean2("setOpts");
		listOpts = (ListOpts) ContextUtils.getBean2("listOpts");
		hashOpts = (HashOpts) ContextUtils.getBean2("hashOpts");
		stringOpts = (StringOpts) ContextUtils.getBean2("stringOpts");
		pipelineOpts = (PipelineOpts) ContextUtils.getBean2("pipelineOpts");
		scriptOpts = (ScriptOpts) ContextUtils.getBean2("scriptOpts");
	}
	
	
	
	private static void initOracleConfig2() {
//		long score = System.currentTimeMillis();
		
		StringBuffer buffer = new StringBuffer();
		
		List<SvrNodeDef> snds = ContextUtils.getBean2(SvrNodeDefDao.class).getAllObj();
		configSvrNodeDefList = snds != null ? snds : new ArrayList<>();	
				
		// 加载禁发时段过滤规则
		Map<String,Set<String>> configForbidTimeMapTmp = new HashMap<>();
		List<ForbidRule> forbids = ContextUtils.getBean2(ForbidRuleDao.class).getAllObj();
		for (ForbidRule forbid:forbids) {
			buffer.setLength(0);
			
			String svrNode = StringUtils.toString(forbid.getSvrNode());
			String serviceCode = StringUtils.toString(forbid.getServiceCode());
			
			buffer.append(svrNode);
			buffer.append(":");
			buffer.append(serviceCode);
			buffer.append(":");
			buffer.append(forbid.getStartTime());
			buffer.append(":");
			buffer.append(forbid.getEndTime());
			buffer.append(":");
			buffer.append(forbid.getForbidRuleId());
			
			String key = svrNode + ":" + serviceCode;
			Set<String> set = configForbidTimeMapTmp.get(key);
			if (set == null) {
				set = new HashSet<>();
				set.add(buffer.toString());
				configForbidTimeMapTmp.put(key, set);
			} else {
				set.add(buffer.toString());
			}
		}
		configForbidTimeMap = configForbidTimeMapTmp;
		
		//加载通道配置
		Map<String,GateDef> configGateDefMapTmp = new HashMap<String, GateDef>();
		List<GateDef> gateDefList = ContextUtils.getBean2(GateDefDao.class).getAllObj();
		for(GateDef gateDef : gateDefList){
			configGateDefMapTmp.put(gateDef.getGateLinkId(), gateDef);
		}
		configGateDefMap = configGateDefMapTmp;
		
		Map<String,Integer> configGateLinkThreadNumMapTmp = new HashMap<String, Integer>();
		if(!StringUtils.isEmpty(gatelinkSendThreadNum)) {
			List<String> list = StringUtils.splitToList(gatelinkSendThreadNum, ",");
			for(String gateLinkThreadNumConfig : list){
				if(StringUtils.isEmpty(gatelinkSendThreadNum)){
					continue;
				}
				List<String> configList = StringUtils.splitToList(gateLinkThreadNumConfig,":");
				if(configList != null && configList.size() >= 2){
					configGateLinkThreadNumMapTmp.put(configList.get(0), StringUtils.toInteger(configList.get(1)));
				}
			}
		}
		configGateLinkThreadNumMap = configGateLinkThreadNumMapTmp;
		
		// 保存运行参数Hash的key到集合RunningParamsHashSet
		setOpts2.add(RunningParamsHashSet, RunningParamsHash);
		
		saveConfigForbidTimeMapToRedis();
	}

	private static void saveConfigForbidTimeMapToRedis() {
		
		pipelineOpts2.save( new ABExcuteCommands() {
			@Override
			public void excute(RedisConnection connection){
				for(String key:configForbidTimeMap.keySet()){
					Set<String> set = configForbidTimeMap.get(key);
					List<byte[]> setBtList = new ArrayList<byte[]>();
					for(String buffer :set){
						setBtList.add(AppStaticConfigs.stringRedisSerializer.serialize(buffer));
					}
					connection.rPush(AppStaticConfigs.stringRedisSerializer.serialize("Forbid" + ":" + key),
							setBtList.toArray(new byte[1][]));
				}
			}
		});
		
	}


}
